Object.defineProperty(exports, "__esModule", {
    value: true
});

exports.City = exports.StartEndAddress = exports.Area = exports.Address = exports.PointList = exports.Point = undefined;

var _createClass = function() {
    function defineProperties(target, props) {
        for (var i = 0; i < props.length; i++) {
            var descriptor = props[i];
            descriptor.enumerable = descriptor.enumerable || false;
            descriptor.configurable = true;
            if ("value" in descriptor) descriptor.writable = true;
            Object.defineProperty(target, descriptor.key, descriptor);
        }
    }
    return function(Constructor, protoProps, staticProps) {
        if (protoProps) defineProperties(Constructor.prototype, protoProps);
        if (staticProps) defineProperties(Constructor, staticProps);
        return Constructor;
    };
}();

var _util = require("./util_2.js");

var _util2 = _interopRequireDefault(_util);

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}

function _possibleConstructorReturn(self, call) {
    if (!self) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
    }
    return call && (typeof call === "object" || typeof call === "function") ? call : self;
}

function _inherits(subClass, superClass) {
    if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
    }
    subClass.prototype = Object.create(superClass && superClass.prototype, {
        constructor: {
            value: subClass,
            enumerable: false,
            writable: true,
            configurable: true
        }
    });
    if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}

function _classCallCheck(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
    }
}

// 站点信息
var Point = function() {
    function Point(lng, lat) {
        _classCallCheck(this, Point);
        //默认中心点
                if (lng instanceof Point) {
            return lng;
        }
        this.lng = lng;
        this.lat = lat;
    }
    _createClass(Point, [ {
        key: "equals",
        value: function equals(point) {
            return this.lat === point.lat && this.lng === point.lng;
        }
    }, {
        key: "longitude",
        set: function set(lng) {
            this.lng = lng;
        },
        get: function get() {
            return this.lng;
        }
    }, {
        key: "latitude",
        set: function set(lat) {
            this.lat = lat;
        },
        get: function get() {
            return this.lat;
        }
    } ]);
    return Point;
}();

Point.defaultPoint = new Point(114.05454, 22.522909);

var PointList = function PointList(pointList) {
    _classCallCheck(this, PointList);
    return pointList.map(function(item) {
        return new Point(item.lng, item.lat);
    });
};

var Address = function() {
    function Address(info) {
        _classCallCheck(this, Address);
        this.setOtherProps(info);
        this.point = new Point(info.lng, info.lat);
        this.setName(info.name || info.stationName || "");
        this.setAliasName(info.alias || "");
        this.computeTextLength();
        // this.nameLength = this.computeTextLength(this.name);
        // this.aliasNameLength = this.computeTextLength(this.aliasName);
                if (!info.valid) {
            this.initTextLength();
        }
    }
    _createClass(Address, [ {
        key: "setTotalLength",
        value: function setTotalLength(totalLength) {
            this.totalLength = totalLength;
        }
    }, {
        key: "initTextLength",
        value: function initTextLength() {
            this.nameLength = 400;
            this.aliasNameLength = 200;
        }
    }, {
        key: "computeTextLength",
        value: function computeTextLength() {
            //一个字节大约占7.5px的宽度
            this.nameLength = _util2.default.getByteLen(this.name) * 15;
            this.aliasNameLength = _util2.default.getByteLen(this.aliasName) * 15;
            if (this.nameLength + this.aliasNameLength > this.totalLength || this.nameLength + this.aliasNameLength === 0) {
                this.nameLength = 400;
                this.aliasNameLength = 200;
            }
        }
    }, {
        key: "setOtherProps",
        value: function setOtherProps(info) {
            Object.assign(this, info);
        }
    }, {
        key: "setName",
        value: function setName(name) {
            this.name = name;
        }
    }, {
        key: "setAliasName",
        value: function setAliasName(aliasName) {
            this.aliasName = aliasName;
        }
    } ]);
    return Address;
}();

var Scope = function() {
    function Scope(info) {
        _classCallCheck(this, Scope);
        this.setId(info.id);
        this.setName(info.name);
        this.setCenter(new Point(info.lng, info.lat));
    }
    _createClass(Scope, [ {
        key: "setId",
        value: function setId(id) {
            this.id = id;
        }
    }, {
        key: "setPath",
        value: function setPath(pointArray) {
            this.path = pointArray;
        }
    }, {
        key: "getPath",
        value: function getPath() {
            return this.path;
        }
    }, {
        key: "setCenter",
        value: function setCenter(point) {
            this.center = point;
        }
        // 设置名称
        }, {
        key: "setName",
        value: function setName(name) {
            this.name = name;
        }
        // 设置上级区域名称
        }, {
        key: "setParentName",
        value: function setParentName(name) {
            this.parentName = name;
        }
    } ]);
    return Scope;
}();

var City = function(_Scope) {
    _inherits(City, _Scope);
    function City(info) {
        _classCallCheck(this, City);
        var _this = _possibleConstructorReturn(this, (City.__proto__ || Object.getPrototypeOf(City)).call(this, info));
        _this.setCityId(info.cityId);
        _this.setLevel(info.level);
        _this.setCode(info.code);
        return _this;
    }
    _createClass(City, [ {
        key: "setCityId",
        value: function setCityId(cityId) {
            this.cityId = cityId;
        }
    }, {
        key: "setLevel",
        value: function setLevel(level) {
            this.level = level;
        }
    }, {
        key: "setCode",
        value: function setCode(code) {
            this.code = code;
        }
    } ]);
    return City;
}(Scope);

var Area = function(_Scope2) {
    _inherits(Area, _Scope2);
    function Area(info) {
        _classCallCheck(this, Area);
        return _possibleConstructorReturn(this, (Area.__proto__ || Object.getPrototypeOf(Area)).call(this, info));
    }
    return Area;
}(Scope);

var StartEndAddress = function() {
    function StartEndAddress(start, end) {
        _classCallCheck(this, StartEndAddress);
        this.setStart(start);
        this.setEnd(end);
    }
    _createClass(StartEndAddress, [ {
        key: "setStart",
        value: function setStart(start) {
            this.start = start || {};
        }
    }, {
        key: "setEnd",
        value: function setEnd(end) {
            this.end = end || {};
        }
    } ]);
    return StartEndAddress;
}();

exports.Point = Point;

exports.PointList = PointList;

exports.Address = Address;

exports.Area = Area;

exports.StartEndAddress = StartEndAddress;

exports.City = City;